<?php

namespace app\admin\model\yunfood;

use addons\yunfood\library\Logic;
use think\Exception;

/**
 * 会员用户
 */
class FundUser extends \addons\yunfood\model\FundUser
{
    // 自定义初始化
    protected static function init()
    {
        self::beforeInsert(function ($record) {
            if (self::get(['user_id' => $record->user_id])) {
                throw new Exception('用户已开通余额账户，不能重复操作');
            }
            $record->number = Logic::generateBusinessNo('fund_user_no');
            $record->status = FundUser::STATUS_NORMAL;
        });
    }

    protected function setExpiredAtAttr($value)
    {
        return $value && ! is_numeric($value) ? strtotime($value) : $value;
    }
}
